<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="css/main.css">
		<title>搭建环境</title>
		<title>addClass demo</title>
		<style>
			div {
				background: white;
			}

			.red {
				background: red;
			}

			.red.green {
				background: green;
			}
		</style>
		<script src="../libs/jquery.3.6.0.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>

		<div>This div should be white</div>
		<div class="red">This div will be green because it now has the "green" and "red" classes.
			It would be red if the addClass function failed.</div>
		<div>This div should be white</div>
		<p>There are zero green divs</p>



		<script>
			$("div").addClass(function(index, currentClass) {
				var addedClass;

				if (currentClass === "red") {
					addedClass = "green";
					$("p").text("There is one green div");
				}

				return addedClass;
			});
		</script>

	</body>
</html>
